import { createRouter, createWebHistory } from "vue-router";

import routesWeb from './routes-web';
import routesAdmin from './routes-admin';

const baseRoutes = [];
const routes = baseRoutes.concat(routesWeb,routesAdmin);

const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to,from,next)=>{
  // to: 将要访问的路径
  // from: 表示从哪个路径跳转过来
  // next: 是一个函数，放行
  if(to.path==='/admin/login') return next();
      // 获取token
      

  if(to.path=='/admin' || to.path=='/main' || to.path=='/user/userList'){
    const tokenStr = window.sessionStorage.getItem('tokenA');
    if(!tokenStr || tokenStr!='249972068') return next('/admin/login');
    next();
  }else{
    return next();
  }
      
});

export default router;
